<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="UTF-8" />
        <title>05_案例练习-开关思想</title>
        <style>
            div {
                width: 200px;
                height: 200px;
                border-radius: 50%;
                border: 1px solid black;
            }
        </style>
    </head>
    <body>
        <div></div>

        <script>
            var div = document.querySelector('div');

            var flag = true;

            div.onclick = function(){
                if(flag){
                    this.style.backgroundColor = 'yellow';
                    // flag = false;
                }else{
                    this.style.backgroundColor = '';
                    // flag = true;
                }

                flag = !flag;
            }

        </script>
    </body>
</html>